package learn.Thread;

//交替打印
public class ThreadVolatile {
    private static volatile int flag = 0;

    public static void main(String[] args) {
        Thread t1 = new Thread(()->{
            for (int i = 0; i < 10; i++) {
                while(flag==0){}
                    System.out.println(i);
                    flag=0;

            }
        });

        Thread t2 = new Thread(()->{
            for (int i = 0; i < 10; i++) {
                char ch = (char) ('A'+i);
                while(flag==1){}
                    System.out.println(ch);
                    flag=1;

            }
        });
        t1.start();
        t2.start();
    }



}
